$OpenBSD: patch-jenscript_jenscript_SH,v 1.7 2010/05/19 14:35:18 espie Exp $
--- jenscript/jenscript.SH.orig	Tue Jan 16 18:20:31 1990
+++ jenscript/jenscript.SH	Wed May 19 14:28:09 2010
@@ -20,14 +20,12 @@ echo "Extracting jenscript (with variable substitution
 : Protect any dollar signs and backticks that you do not want interpreted
 : by putting a backslash in front.  You may delete these comments.
 $spitshell >jenscript <<!GROK!THIS!
-#!$perlloc -P
+#!$perlloc
 #
 #	Convert Text Files into PostScript Format
 #
 #			1989 3/28 MASUI Toshiyuki
 #
-eval "exec $perlloc -P -S \$0 \$*"
-	if \$Shell_cannot_understand;
 !GROK!THIS!
 
 : In the following dollars and backticks do not need the extra backslash.
@@ -35,6 +33,7 @@ $spitshell >>jenscript <<'!NO!SUBS!'
 ($program) = ($0 =~ m#([^/]+)$#);
 
 $mflag = $gflag = $xflag = $nflag = $sflag = $dflag = $eflag = $kflag = 0;
+$tflag = 0;
 $columns = 1;
 $curcolumn = 0;
 $printpage = 0;
@@ -61,6 +60,7 @@ while($_ = $ARGV[0], /^-/){ # get options
 		elsif(s/^d//){ $dflag = 1; }
 		elsif(s/^E//){ $eflag = 1; }
 		elsif(s/^k//){ $kflag = 1; }
+		elsif(s/^t//){ $tflag = 1; }
 		elsif(s/^(\d)//){ $columns = $1; }
 		elsif(/^f$/){ $kfont = $ARGV[0]; shift; last; }
 		elsif(/^f(.+)/){ $kfont = $1; last; }
@@ -87,27 +87,33 @@ $afont ne "" ? ($afont, $afont, $afont, $afont, $afont
 $xflag ? ("Courier", "Courier-Bold", "Courier-Oblique", "Courier", "Courier") :
   ("Times-Roman", "Times-Bold", "Times-Italic", "Times-Roman", "Times-Roman");
 
-($height, $width, $offsetx, $offsety) = 
-	$sflag ? (650, 440, 120, 150) : # B5
-#		 (730, 550, 60, 60);	# A4
-		 (700, 550, 60, 40);	# letter
+($PageHeight, $PageWidth, $PageOffset) =
+	$sflag ? (842, 596, 60):	# A4
+	         (792, 612, 40);	# letter
+$offsetx = $offsety = $PageOffset;
+$height = $PageHeight - 2 * $offsety;
+$width = $PageWidth - 2 * $offsetx;
+# LandScape turn
+($height, $width, $offsetx, $offsety) = ($width, $height, $offsety, $offsetx)
+	if ($tflag);
 $linepitch = $lines ? $height / $lines : $fontsize * 7.0 / 6.0;
 ($kfont, $jfontsize) = $kfont ne "" ? ($kfont, $fontsize) :
-			$fontsize < 5 ? ("jis16", 3.84) :
+#			$fontsize < 5 ? ("jis16", 3.84) :
 			$fontsize < 7 ? ("jis24", 5.76) :
 			$fontsize < 12 ? ("jis32", 7.68) :
-			("jis50", 12) ;
+			("jis48", 12) ;
 $_ = $kfont;
 $texfont = /^jisj/ || /^dmj/ || /^dgj/ ;
 
-#define NORMAL 0
-#define COMMENT 1
-#define STRING 2
-#define LITERAL 3
-#define KEYWORD 4
+
+use constant NORMAL => 0;
+use constant COMMENT => 1;
+use constant STRING => 2;
+use constant LITERAL => 3;
+use constant KEYWORD => 4;
+use constant VGRINDEFS => '/usr/share/misc/vgrindefs';
 $mode = $outmode = NORMAL;
 
-#define VGRINDEFS "/usr/lib/vgrindefs"
 if(! open(vdef,VGRINDEFS)){
 	$language = "";
 }
@@ -132,6 +138,8 @@ if($language){
 		s/\\:/<COLON>/g;
 		split(/:/);
 		$pat = $_[0];
+		# handle C++
+		$pat =~ s/\+/\\+/g;
 		shift(@_);
 		next if $language !~ /^($pat)$/;
 		$pb = $bb = $be = $cb = $ce = $sb =
@@ -295,7 +303,7 @@ while(<>){
 nextline:
 	do flush();
 	$posx = 0;
-	if(($posy -= $linepitch) <= 0){
+	if(m/^\s*\cl\s*$/ || (($posy -= $linepitch) <= 0)){
 		if(++$curcolumn >= $columns){
 			do endpage(1);
 			$curcolumn = 0;
@@ -417,13 +425,17 @@ sub prologue {
 	print "%%Creator: jenscript\n" if ! $nflag;
 	print "%%Title: Jenscript\n" if ! $nflag;
 	print "%%CreationDate: $date\n" if ! $nflag;
+	print "%%BoundingBox: 0 0 $PageWidth $PageHeight\n";
+	print "%%Orientation: Landscape\n" if $tflag;
 	print "%%EndComments\n" if ! $nflag;
 	print "%%DocumentFonts: $kfont",$afont ne "" ? " $afont" : "", "\n";
 	print "save/EnscriptJob exch def\n";
 	print "/StartEnscriptDoc{\$enscript begin}def\n";
 	print "/\$enscript 60 dict def \$enscript begin\n";
 	print "/EndEnscriptDoc{end}def\n";
-	print "/StartPage{/svpg save def }def\n";
+	print "/StartPage{/svpg save def\n";
+	print "[ 0 1 -1 0 $PageWidth 0 ] concat\n" if $tflag;
+	print "}def\n";
 	print "/EndPage{svpg restore showpage}def\n";
 	print "/SetStTime{statusdict /manualfeedtimeout 120 put} def\n";
 	print "/SetStatus{statusdict /manualfeed true put\n";
@@ -445,7 +457,7 @@ sub prologue {
 		print "/FK { /$keywordfont findfont [$xfontsize 0 0 $fontsize 0 0] makefont setfont } bind def\n";
 		print "/FC { /$commentfont findfont [$xfontsize 0 0 $fontsize 0 0] makefont setfont } bind def\n";
 		print "/FS { /$stringfont findfont [$xfontsize 0 0 $fontsize 0 0] makefont setfont } bind def\n";
-		print "/FL { /$litefalfont findfont [$xfontsize 0 0 $fontsize 0 0] makefont setfont } bind def\n";
+		print "/FL { /$literalfont findfont [$xfontsize 0 0 $fontsize 0 0] makefont setfont } bind def\n";
 	}
 	print "/FJ { /$kfont findfont $jfontsize scalefont setfont } bind def\n";
 	print "/N { FN show } bind def\n";
